package com.lee.chapter01;

import java.util.concurrent.TimeUnit;

public class Test_Volatile {
    static volatile int num = 1;

    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            while (num != 100) {
                Thread.yield();
            }

            System.out.println(num);
        });

        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                num++;
                try {
                    TimeUnit.MILLISECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        thread1.start();
        thread2.start();
    }
}
